﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Game_Engine
{
    public class Button : GUIElement
    {
        public Button(Texture2D texture, Rectangle rectangle, String text, Color background, Color textColor)
        {
            Texture = texture;
            BackgroundColor = background;
            Bounds = rectangle;
            Text = text;
            TextColor = textColor;
            Selected = false;
        }

        public override void Update()
        {
            if ((InputManager.KeyPressed(Keys.Enter) && Selected) || (InputManager.MousePressed(0) && Bounds.Contains(InputManager.GetMousePosition())))
                OnAction();

            base.Update();
        }

        public override void Draw(SpriteBatch spriteBatch, SpriteFont font)
        {
            base.Draw(spriteBatch, font);
            spriteBatch.DrawString(font, Text, new Vector2(Bounds.X, Bounds.Y), TextColor);
        }
    }
}
